$(function() {
	$('#my-table').dataTable().fnDestroy();
	oTable = $('#my-table').DataTable({
		"processing" : true, //加载数据时显示正在加载信息   
		"serverSide" : true, //指定从服务器端获取数据   
		"searching" : false,
		"lengthChange" : false, //用户不可改变每页显示数量   
		"ordering" : false,
		"aLengthMenu" : [ 10 ],//设置一页展示10条记录

		"ajax" : {
			"url" : "/btsb/hzlist",
			"dataType" : "json",
			"type" : "post",
			"dataSrc" : "rowsData",
			"data" : function(d) {
				d.hzzt = $('#hzzt').val();
				/*d.startDate = $('#startDate').val();
				d.endDate = $('#endDate').val();*/
			}
		},
		"columns" : [{
			"data" : null
		},{
			"data" : "qyqc"
		}, {
			"data" : "tbsj"
		}, {
			"data" : "sbjd"
		}, {
			"data" : "hzzt"
		},  {
			"data" : "id"
		} ],
		"columnDefs" : [{
			"targets" : 0,
			"width" : "10%",
			"render" : function(data, type, row, meta) {
				// 显示行号  
                var startIndex = meta.settings._iDisplayStart;  
                return startIndex + meta.row + 1;  
			}
		},{
			"targets" : 1,
			"width" : "15%",
			"render" : function(data, type, row, meta) {
				return row.yhxxVO.qyqc;
			}
		}, {
			"targets" : 2,
			"width" : "15%",
			"render" : function(data, type, row, meta) {
				if (data != null && data != "")
					return date2String(data);
				return "";
			}
		},{
			"targets" : 3,
			"width" : "15%",
			"render" : function(data, type, row, meta) {
				return row.sbnf.toString()+"年第"+data + "季度";
			}
		},{
			"targets" : 4,
			"width" : "15%",
			"data" : "id",
			"render" : function(data, type, row, meta) {
				var status = "";
				if (row.hzzt==0){
					status = "未申报";
				}else if (row.hzzt==1){
					status = "审核中";
				}else if (row.hzzt==2){
					status = "审核中";
				}else if (row.hzzt==3){
					status = "已通过";
				}else if (row.hzzt==4){
					status = "未通过";
				}
				return status;
			}
		},{
			"targets" : 5,
			"width" : '30%',
			"data" : "id",
			"render" : function(data, type, row, meta) {
				var buttons = "";
				
				if (row.hzzt==3) {
					buttons += "<a href='/btsb/downtslysqd?sbnf=" + row.sbnf + "&sbjd=" + row.sbjd; 
					buttons += "' class='am-btn am-btn-xs am-text-secondary'><span class='am-icon-newspaper-o'></span> 补贴申请表下载</a>";
				}
					
				return buttons;
			}
		}]
	});
})

function publish(id){
	$.ajax( {  
        type : 'POST',  
        url : '/btsb/publish',
        data: 'id='+id,
        dataType:"json",  
        success : function(data) {  
        	var status = data.status;
        	var errormsg = data.errormsg;
        	var errordata = data.errordata;
        	if(status==0){   		
        		alert('发起成功');
        		search();
        	}else if(status==-1){
        		alert(errormsg+'提单号:'+errordata);
        		window.location.href='/btsb/addslglindex';
        	}else{
        		window.location.href='/btsb/addtlglindex';
        		alert(errormsg+'货票号:'+errordata);
        	}
        },  
        error : function(data) {  
          alert("失败");
        }  
      });
}